<template>
	<view class="s-container">
		<!--新闻列表-->
		<view class="s-news-view" v-if="consult_list.length">
			<block v-for="(item,index) in consult_list" :key="index">
				<s-list-cell :index="index" @tap="consult_detail(item.id)">
					<view class="s-news-flex" :class="item.images_arr.length>1 ? 's-flex-column':'s-flex-start'">
						<view class="s-news-picbox" :class="[item.images_arr.length>1?'s-w-full':'s-w220 s-h165',item.images_arr.length>1?'s-flex-between':'']" v-if="item.images_arr.length>0">
							<block v-for="(it,ind) in item.images_arr" :key="ind">
								<image :src="it" mode="widthFix" class="s-block"  :class="[item.images_arr.length==3?'s-one-third':'',item.images_arr.length==1?'s-w-full':'',item.images_arr.length==2?'s-one-three':'']"></image>
							</block>
						</view>
						<view class="s-news-tbox s-flex-column s-flex-between" :class="[item.images_arr.length==1?'s-h165 s-pl-20':'']">
							<view class="s-news-title s-pt20">{{item.title}}</view>
							<view class="s-sub-box s-pt20">
								<view class="s-sub-source">作者：{{item.author}}</view>
								<view class="s-sub-cmt">
									<view>阅读量{{item.reading_quantity}}</view>
								</view> 
							</view>
						</view>
					</view>
				</s-list-cell>
			</block>
		</view> 
		<s-no-data v-if="consult_list.length<=0&&moreData===false" :fixed="true" :imgUrl="$s.config.getConfig('NoDataImgUrlA')">
			{{$s.config.getConfig('NoDataTitle')}}
		</s-no-data>
		<s-loadmore v-if="moreData"></s-loadmore>
		<s-nomore v-if="consult_list.length>0&&moreData===false"></s-nomore>
		<s-scroll-top :scrollTop="scrollTop"></s-scroll-top>
	</view>	
</template>
<script>
	export default {
		data() {
			return {
				key:'',
				scrollTop: 0,
				paging:null,
				moreData:true, 
				consult_list:[] //咨询列表
			}
		},
		async onLoad(options){
			this.key = options.key
			await this.getConsult()
		},
		methods: { 
			async getConsult(){
				const paging =  this.$s.model.consult.getConsult({key:this.key})
				this.paging = paging
				const res = await paging.getMoreData()
				if (!res) {
					return
				}
				this.consult_list = res.accumulator
				this.moreData = res.moreData
			},
			//跳转列表详情
			async consult_detail(id){
				return await this.$s.uniApi.navigateTo({url:'../consult_detail/consult_detail?id='+id});
			}
		},
		//下拉刷新
		async onPullDownRefresh() {
			await this.getConsult()
			uni.stopPullDownRefresh()
		},
		//上拉加载更多
		async onReachBottom() {
			const res = await this.paging.getMoreData()
			if(!res){
				return
			}
			this.consult_list = res.accumulator
			this.moreData = res.moreData
		}
	}
</script>
<style lang="scss" scoped>
@import 'consult_list.scss';
</style>
